package com.lime49.lockcrypt;
import com.lime49.lockcrypt.ui.AbstractDialog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.URL;
import java.text.MessageFormat;

/**
 * A dialog which displays information about the special format used for password generation
 */
public class FrmPWGenSpecialFormat extends AbstractDialog {
    private ResourceBundle lang;
    
    public FrmPWGenSpecialFormat(JDialog owner, ResourceBundle lang) {
        super(owner, lang.getString("FORMAT"), true);
        this.lang = lang;
        try {
            URL iconURL = this.getClass().getResource("images/bulb_16.png");
            this.setIconImage(new ImageIcon(iconURL).getImage());
        } catch(Exception ignore) {/**/}
        KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        Action escapeAction = new AbstractAction() {
            // close the frame when the user presses escape
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        }; 
        this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
        this.getRootPane().getActionMap().put("ESCAPE", escapeAction);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JPanel content = new JPanel(new GridBagLayout());
            content.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
        this.setContentPane(content);
            GridBagConstraints c = new GridBagConstraints();
            c.insets = Constants.GLOBALINSETS;
            c.ipadx = 5;
            c.weighty = 1;
            int curY = 0;
            JTextArea lblInfo = new JTextArea();
                lblInfo.setText(lang.getString("PWGEN_SPECIALFORMATINFO"));
                lblInfo.setBackground(null);
                lblInfo.setEditable(false);
                lblInfo.setBorder(null);
                lblInfo.setLineWrap(true);
                lblInfo.setWrapStyleWord(true);
                Utils.setgrid(c,curY,0,2,1,GridBagConstraints.BOTH,GridBagConstraints.CENTER,0.5);
                content.add(lblInfo,c);
                curY++;
            JLabel lblSymbol = new JLabel(lang.getString("SYMBOL"));
                lblSymbol.setFont(lblSymbol.getFont().deriveFont(Font.BOLD));
                Utils.setgrid(c,curY,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.5);
                content.add(lblSymbol,c);
            JLabel lblMeaning = new JLabel(lang.getString("MEANING"));
                lblMeaning.setFont(lblSymbol.getFont());
                Utils.setgrid(c,curY,1,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.5);
                content.add(lblMeaning,c);
                curY++;
            JLabel lblAnySymbol = new JLabel("*");
                Utils.setgrid(c,curY,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.5);
                content.add(lblAnySymbol,c);
            JLabel lblAny = new JLabel(lang.getString("PWGEN_ANYCHARACTER"));
                Utils.setgrid(c,curY,1,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.5);
                content.add(lblAny,c);
                curY++;
            JLabel lblUppercaseSymbol = new JLabel("C");
                Utils.setgrid(c,curY,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.5);
                content.add(lblUppercaseSymbol,c);
                MessageFormat fmtUppercase = new MessageFormat(lang.getString("PWGEN_UPPERCASE"));
            JLabel lblUppercase = new JLabel(fmtUppercase.format(new Object [] {"A-Z"}));
                Utils.setgrid(c,curY,1,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.5);
                content.add(lblUppercase,c);
                curY++;
            JLabel lblLowercaseSymbol = new JLabel("c");
                Utils.setgrid(c,curY,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.5);
                content.add(lblLowercaseSymbol,c);
                MessageFormat fmtLowercase = new MessageFormat(lang.getString("PWGEN_LOWERCASE"));
            JLabel lblLowercase = new JLabel(fmtLowercase.format(new Object [] {"a-z"}));
                Utils.setgrid(c,curY,1,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.5);
                content.add(lblLowercase,c);
                curY++;
                MessageFormat fmtDigits = new MessageFormat(lang.getString("PWGEN_DIGITS"));
            JLabel lblDigitsSymbol = new JLabel("d");
                Utils.setgrid(c,curY,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.5);
                content.add(lblDigitsSymbol,c);
            JLabel lblDigits = new JLabel(fmtDigits.format(new Object [] {"0-9"}));
                Utils.setgrid(c,curY,1,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.5);
                content.add(lblDigits,c);
                curY++;
            JLabel lblBracketsSymbol = new JLabel("b");
                Utils.setgrid(c,curY,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.5);
                content.add(lblBracketsSymbol,c);
                MessageFormat fmtBrackets = new MessageFormat(lang.getString("PWGEN_BRACKETS"));
            JLabel lblBrackets = new JLabel(fmtBrackets.format(new Object [] {" {},[],(), <> "}));
                Utils.setgrid(c,curY,1,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.5);
                content.add(lblBrackets,c);
                curY++;
            JLabel lblExtendedSymbol = new JLabel("e");
                Utils.setgrid(c,curY,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.5);
                content.add(lblExtendedSymbol,c);
            JLabel lblExtended = new JLabel(lang.getString("PWGEN_EXTENDED"));
                Utils.setgrid(c,curY,1,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.5);
                content.add(lblExtended,c);
                curY++;
            JLabel lblSpecialSymbol = new JLabel("s");
                Utils.setgrid(c,curY,0,1,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,0.5);
                content.add(lblSpecialSymbol,c);
                MessageFormat fmtSpecial = new MessageFormat(lang.getString("PWGEN_SPECIAL"));
            JLabel lblSpecial = new JLabel(fmtSpecial.format(new Object [] {"!,\",£,$,%,^", lang.getString("ETC")}));
                Utils.setgrid(c,curY,1,1,1,GridBagConstraints.NONE,GridBagConstraints.NORTHWEST,0.5);
                content.add(lblSpecial,c);
                curY++;
            JButton btnOk = new JButton(lang.getString("OK"));
                btnOk.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) { dispose(); }
                });
                //btnOk.setMinimumSize(Constants.MINSIZE);
                btnOk.setPreferredSize(Constants.PREFSIZE);
                btnOk.setMaximumSize(Constants.MAXSIZE);
                Utils.setgrid(c,curY,0,2,1,GridBagConstraints.NONE,GridBagConstraints.CENTER,1);
                content.add(btnOk,c);
                curY++;
        this.setMinimumSize(new Dimension(110,350));
        this.setMaximumSize(new Dimension(250,600));
        this.pack();
    }
}
